const BaseHandler     = require('../base-handler');
const HTTP_VERBS      = require('../../../constants').HTTP_VERBS;

class PhotoActionHandler extends BaseHandler {
    get pattern() {
        return '/walls/:wall_id/photos/:photo_id/:action';
    }

    doPOST(request, response) {
        var wallId = request.params.wall_id;
        var photoId = request.params.photo_id;
        var action = request.params.action;
        var userId = request.session.user.id || request.session.walls[request.params.wall_id].wall_user_id;
        this.Controller.doPhotoAction(action, wallId, photoId, userId, null, (data) => {
            var result = {
                success: true
            };
            if(data === null) {
                result.success = false;
                result.error = "Interal error";
            } else {
                result.data = data;
            }
            response.json(result);
        });
    }

    setup() {
        this.registerVerb(HTTP_VERBS.POST, this.doPOST);
    }
}

module.exports = PhotoActionHandler;